﻿using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;

namespace Silent.API.LastFm.Requests
{
    public class ArtistSearchRequest : RequestBase<List<Artist>>
    {
        public ArtistSearchRequest(string apiKey, string artist)
            : base(apiKey, QueryConstants.ARTIST_GET_INFO)
        {
            parameters.AddRange(new[] {
                new QueryParameter(QueryConstants.PREFIX_ARTIST, artist)
            });
        }

        public override List<Artist> Request()
        {
            var query = new QueryBuilder().BuildQuery(parameters.ToArray());
            var elements = XElement.Load(query).Descendants("artist");
            var objects = elements.Select(Converter.ConvertToArtist).ToList();
            return objects;
        }
    }
}